#include <glib.h>

gint main(gint argc, gchar **argv)
{
    GList *list = NULL;
    GList *l = NULL;
    gint n = 0;

    list = g_list_append(list, GINT_TO_POINTER(1));
    list = g_list_append(list, GINT_TO_POINTER(3));
    list = g_list_append(list, GINT_TO_POINTER(5));
    list = g_list_append(list, GINT_TO_POINTER(7));

    l = g_list_nth(list, 1);
    g_print("nth(list,1) element: %d \n", (NULL == l) ? 99999 : GPOINTER_TO_INT(l->data));

    n = GPOINTER_TO_INT(g_list_nth_data(list, 1));
    g_print("nth_data(list,1) element: %d \n", n);

    l = g_list_last(list);
    //7->5->3->1
    l = g_list_nth_prev(l, 3);
    g_print("nth_prev(last,3) element: %d \n", (NULL == l) ? 99999 : GPOINTER_TO_INT(l->data));

    l = g_list_last(list);
    n = g_list_position(list, l);
    g_print("last position: %d \n", n);

    n = g_list_index(list, GINT_TO_POINTER(5));
    g_print("element 5 position: %d \n", n);

    l = g_list_find(list, GINT_TO_POINTER(5));
    g_print("element 5 data: %d \n", (NULL == l) ? 99999 : GPOINTER_TO_INT(l->data));

    g_list_free(list);

    return 0;
}